/**
 * @作者:黎谢之
 * @创建时间：2021/7/7
 * @修改时间：2021/7/10
 */
package com.example.senior_bug.controller;

import com.example.senior_bug.ToolClass.Result;
import com.example.senior_bug.Service.SKUService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@CrossOrigin
@RequestMapping("/SKU")
public class SKUController {

    @Autowired
    private SKUService skuService;

    //测试路由
    @RequestMapping("/All")
    public Result FindAllSku() {
        return skuService.FindAllSku();
    }

    //用户二级界面切换品牌
    @RequestMapping("/getSameCategory")
    public Result GetSkuByCategory(@RequestParam String CategoryName, @RequestParam int Take,
                                   @RequestParam int Page, @RequestParam String Type) {
        return skuService.GetSkuByCategory(CategoryName, Take, Page, Type);
    }

    //用户二级页面获取Sku列表
    @RequestMapping("/getList")
    public Result GetSkuByCategoryAndBrandAndTakeAndPage
    (@RequestParam(required = true) String CategoryName, @RequestParam String BrandName,
     @RequestParam int Take, @RequestParam int Page, @RequestParam String Type) {
        return skuService.GetSkuByCategoryAndBrandAndTakeAndPage(CategoryName, BrandName, Take, Page, Type);
    }

    //获取对应二级分类下对应品牌的商品总数
    @RequestMapping("/getSum")
    public Result GetSumByCategoryNameAndBrandName(@RequestParam String CategoryName, @RequestParam String BrandName) {
        return skuService.GetSumOfSkuByCategoryNameAndBrandName(CategoryName, BrandName);
    }

    //用户查看商品详情页面获取对应Sku对象信息
    @RequestMapping("/getOne")
    public Result GetSkuById(@RequestParam(required = true) int Id) {
        return skuService.GetSkuById(Id);
    }

    //模糊搜索商品
    @RequestMapping("/find")
    public Result FindSkuByKeyWords(@RequestParam String KeyWords) {
        return skuService.FindSkuByKeyWords(KeyWords);
    }

    //获取所有分类选项
    @RequestMapping("/GetAllOptions")
    public Result GetAllOptions() {
        return skuService.GetAllOption();
    }

    //根据销量前几获取商品
    @RequestMapping("/GetSales")
    public Result GetSales() {
        return skuService.getSortBySales();
    }

}
